package com.ptswitch.material.pages.visitor;

import javax.servlet.http.HttpServletResponse;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ptswitch.material.pages.base.PageBase;
import com.ptswitch.material.service.LoginInfoService;
import com.ptswitch.material.util.WebUtil;

public class Logout extends PageBase {

    @InjectPage
    private Login login;
    @Inject
    private HttpServletResponse response;
    @Inject
    private LoginInfoService loginInfoSer;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object logout() {
        loginInfoSer.delete(getLoginInfo());
        response.addCookie(WebUtil.addUsernameCookie(null));
        response.addCookie(WebUtil.addLoginTokenCookie(null));
        return login;
    }
}
